import { isNullOrWhiteSpece } from '@jctech/utils/is';

const filterRule = [
  [/&/g, '&amp;'],
  [/</g, '&lt;'],
  [/>/g, '&gt;'],
  [/\"/g, '&quot;'],
  [/\'/g, '&#39;'],
  [/\//g, '&#x2F;']
];

export function xssHtmlFilter(html) {
  if (isNullOrWhiteSpece(html)) {
    return '';
  }
  html = String(html);
  filterRule.forEach(([regexp, result]) => {
    html = html.replace(regexp, result);
  });
  return html;
}
